// CONSOLE

// 输出到调试终端


// [[file:~/literate-programming/soul-hunter-awakening-damage-calculator-web-edition.org::*CONSOLE][CONSOLE:1]]
function testsReport(){
    import("./tests.module.js").then(function(Tests){
        Tests.report()
    })
}
/* testsReport() */

function samplesReport(){
    import("./samples.module.js").then(function(Samples){
        Samples.report()
    })
}
/* samplesReport() */
// CONSOLE:1 ends here
// DOCUMENT

// 输出到网页


// [[file:~/literate-programming/soul-hunter-awakening-damage-calculator-web-edition.org::*DOCUMENT][DOCUMENT:1]]
function htmlToObject(){
    console.log(ObjectHTML.HTMLToObject(document.getElementById("board")))
}

/* htmlToObject() */
// DOCUMENT:1 ends here
// ONCHANGE

// 修改表单后实时显示输出计算结果


// [[file:~/literate-programming/soul-hunter-awakening-damage-calculator-web-edition.org::*ONCHANGE][ONCHANGE:1]]
function filter(board){
    let objects=Sample.report([
        Sample.option(Database.localStorageGet("Database.optionsName")||"基础方案",Sample.copyOptions()),
        Sample.option(
            ObjectHTML.getTitle(),
            ObjectHTML.HTMLToObject(board)
        )
    ])
    ObjectHTML.formatFilter(Sample.filter(objects[1]),board,"filter",4)
}
function onChange(event){
    filter(this)
    autoSave(board)
}
// ONCHANGE:1 ends here
// autoSave


// [[file:~/literate-programming/soul-hunter-awakening-damage-calculator-web-edition.org::*autoSave][autoSave:1]]
function autoSave(boardElement){
    let titles=[]
    let autoSaveTitle="自动存档"
    Database.localStorageGet("Database.options").forEach(function(option){
        titles.push(option.标题)
    })
    Database.saveToRam(Sample.option(autoSaveTitle,ObjectHTML.HTMLToObject(boardElement)))
}
// autoSave:1 ends here
// INIT

// 初始化


// [[file:~/literate-programming/soul-hunter-awakening-damage-calculator-web-edition.org::*INIT][INIT:1]]
import * as Sample from "./sample.module.js"
import * as ObjectHTML from "./objectHTML.module.js"
import * as Database from "./database.module.js"

function init(){
    /* 总是恢复默认的基础方案 */
    Database.saveToRam(
        Sample.option(
            "基础方案",
            Sample.copyOptions()))
    let board=ObjectHTML.getBoardElement()
    Database.restoreDefaultOptions()
    ObjectHTML.objectToHTML(Sample.copyOptions(),board)
    filter(board)
    board.addEventListener("change",onChange)
}

init()
// INIT:1 ends here
